#include "token.h"
#include <cstring>

char TokenCodeName[][100] = {
	"NONE",
	"ID",
	"NUMBER",
	"ASSIGNOP",
	"RELOP",
	"ADDOP",
	"MULOP",
	"SEMICOL",
	"COLON",
	"COMMA",
	"DOT",
	"DOTDOT",
	"LPAREN",
	"LBRACKET",
	"LSQBRACKET",
	"RPAREN",
	"RBRACKET",
	"RSQBRACKET",
	"EOF",
	"ERROR",
	"ERROR2",
	"PROGRAM",
    "VAR",
    "ARRAY",
    "OF",
	"INTEGER",
	"REAL",
    "FUNCTION",
    "PROCEDURE",
    "BEGIN",
    "END",
    "IF",
    "THEN",
    "ELSE",
	"WHILE",
    "DO",
    "NOT",
    "NEWLINE",
    "SPACE",
    "COMMENT",
    "TAB"
};


char OpTypeName[][100] = {
	"PLUS",
	"MINUS",
	"OR",
	"MULT",
	"DIVIDE",
	"AND",
	"DIV",
	"MOD",
	"LT",
	"GT",
	"LE",
	"GE",
	"EQ",
	"NE"
};

	Token::Token()
	{
		//constructor
	}

	// Get operations
	TokenCode Token::getTokenCode(void) const
	{
		return m_tokenCode;
	}

	DataType Token::getDataType(void) const
	{
		return m_dataType;
	}

	DataValue Token::getDataValue(void) const
	{
		return m_dataValue;
	}

	SymbolTableEntry* Token::getSymTabEntry(void) const
	{
		return m_symtabEntry;
	}

	// Set operations
	void Token::setTokenCode(const TokenCode tc)
	{
		m_tokenCode = tc;
	}

	void Token::setDataType(const DataType type)
	{
		m_dataType = type;
	}

	 void Token::setDataValue(const char *val)
	 {
	   strcpy( m_dataValue.lexeme, val);
		//printf ("%s \n", (char*)"setDataValue:" );
		//printf ("%s \n", m_dataValue.lexeme );
	   //m_dataValue.lexeme = &val;
	 }

	void Token::setDataValue(const OpType oper)
	{
		m_dataValue.op = oper;
	}

	void Token::setSymTabEntry(SymbolTableEntry* entry)
	{
		m_symtabEntry = entry;
	}


	char* Token::tokenCodeToString(void)
	{
		return TokenCodeName[m_tokenCode];
	}

	char* Token::tokenCodeToString(TokenCode tc)
	{
		return TokenCodeName[tc];
	}


	char* Token::opCodeToString(void)
	{
		char* temp = new char;
		temp = OpTypeName[m_dataValue.op];
		return temp;
	}

